#include"lottery_sys.h"
 /*
 该函数用于：对个人信息的处理，包括，显性打印个人信息；修改密码；注销用户
pos_info:
无返回值
参数：用户链表头结点，该用户的节点
print_posinfo:
无返回值
参数：该用户的节点
chpwd:
无返回值
参数：该用户的节点
logoff:
无返回值
参数：用户链表头结点，该用户的节点
*/


void pos_info(Buyer_t* user_head,Buyer_t* user)
{
	char chose = 0;
	while(1)
	{
		printf("请选择：");
		scanf("%c",&chose);
		cleaninput();
		switch(chose)
		{
			case '1':
				print_posinfo(user);
				break;
			case '2':
				chpwd(user);
				break;
			case '3':
				logoff(user_head,user);
				printf("链表已保存！\n");
				return;
			default:
				return;

		}
	}
}

void logoff(Buyer_t* user_head,Buyer_t* user)
{
	char chose = 0;
	int three = 4;
	char passwd[100] = {0};
	Buyer_t* tmp = NULL;
	Buyer_t* tmp_pre = NULL;
	tmp_pre = user_head;
	tmp = user_head -> next;
	while(tmp != NULL)
	{
		if(!strcmp(tmp -> B_name,user -> B_name))
		{
			printf("你确定要注销你的帐号吗？");
			scanf("%c",&chose);
			cleaninput();
			//printf("%c%d",chose,chose);
			if(chose == 'y' || chose == 'Y')
			{
				while(three--)
				{
					printf("请输入原始密码：");
					scanf("%s",passwd);
					cleaninput();
					if(!strcmp(passwd,user -> B_passwd))
					{
						tmp_pre -> next = tmp -> next;
						free(tmp);
						save_user_list(user_head);
						printf("注销成功！3秒后将退出程序...... \n");
						sleep(3);
						exit(0);
					}
					else
					{
						printf("密码不匹配！\n");
						if(three == 1)
						{
							printf("对不起，注销时密码错误过多，本次注销无效！\n");
							return;
						}
					}
				}
			}
			else 
			{
				printf("看来你是后悔了！哈哈哈\n");
				sleep(2);
				break;
			}
		}
		else
		{
			tmp = tmp -> next;
			tmp_pre = tmp_pre -> next;
		}
	}
}

void chpwd(Buyer_t* user)
{
	int three = 4;
	char passwd[100] = {0};
	char passwd2[100] = {0};
	while(three--)
	{
		printf("请输入原始密码：");
		scanf("%s",passwd);
		cleaninput();
		if(!strcmp(passwd,user -> B_passwd))
		{
			printf("请输入新的密码：");
			scanf("%s",passwd);
			cleaninput();
			printf("请输入确认密码：");
			scanf("%s",passwd2);
			cleaninput();
			if(strcmp(passwd,passwd2))
			{
				printf("密码不匹配！\n");
				if(three == 1)
				{
					printf("对不起，密码修改时错误过多，本次修改无效！\n");
					break;
				}
			}
			else
			{
				printf("恭喜你，密码修改成功！\n");
				strcpy(user -> B_passwd,passwd);
				break;
			}
		}
		else
			printf("密码输入错误！\n");
	}
}

void print_posinfo(Buyer_t* user)
{
	printf("\t你的信息如下：\n");
	printf("\t你的ID：%d\n",user -> ID);
	printf("\t账户名：%s\n",user -> B_name);
//	printf("\t密码：%s\n",user -> B_passwd);
	printf("\t剩余金额：%f\n",user -> B_remain_money);
	//	printf("%s",user -> B_passwd);
	//	printf("%s",user -> B_passwd);
}
